<?php 

namespace Api\Manage;

// +----------------------------------------------------------------------
// | 文件 SysNoticeManage.class.php
// +----------------------------------------------------------------------
// | 说明 分析处理有系统消息通知的用户操作
// +----------------------------------------------------------------------
// | 全静态方法调用
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

// finish??? 完成  fail??? 失败  after???  在什么之后
use Api\Event\UserAuthEvent;


class SysNoticeManage {

    // 用户首次注册
    static public function finishReg($uid)
    {
        event('UserNotice')->addSystem($uid, '欢迎来到66play');
    }

    // 完成播放
    static public function afterPlay(&$video, &$user = null, $step = 1)
    {
        !defined('SYS_NOTICE_FIRST_PLAY_LINE') && define('SYS_NOTICE_FIRST_PLAY_LINE', 100);
        if ($video['statis']['play'] == SYS_NOTICE_FIRST_PLAY_LINE - $step){ // 如果在播放之前是99 之后就是100
            $content = sprintf("你发布的%s视频%s数突破%s人啦", $video['title'], '播放', SYS_NOTICE_FIRST_PLAY_LINE);
            event('UserNotice')->addSystem($video['uid'], $content, ['target_id' => $video['id']]);
        }
    }

    // 完成点赞
    static public function afterLike(&$video, &$user = null)
    {
        if (!defined('SYS_NOTICE_FIRST_COMMENT_LINE')){
            define('SYS_NOTICE_FIRST_LIKE_LINE', 100);
        }
        if ($video['statis']['zan'] == SYS_NOTICE_FIRST_LIKE_LINE){ // 如果在播放之前是99 之后就是100
            $content = sprintf("你发布的%s视频%s数突破%s人啦", $video['title'], '点赞', SYS_NOTICE_FIRST_LIKE_LINE);
            event('UserNotice')->addSystem($video['uid'], $content, ['target_id' => $video['id']]);
        }
    }

    // 完成评论
    static public function afterComment(&$video, &$user = null)
    {
        !defined('SYS_NOTICE_FIRST_COMMENT_LINE') && define('SYS_NOTICE_FIRST_COMMENT_LINE', 100);
        if ($video['statis']['comments'] == SYS_NOTICE_FIRST_COMMENT_LINE - 1){ // 如果在播放之前是99 之后就是100
            $content = sprintf("你发布的%s视频%s数突破%s人啦", $video['title'], '评论', SYS_NOTICE_FIRST_COMMENT_LINE);
            event('UserNotice')->addSystem($video['uid'], $content, ['target_id' => $video['id']]);
        }
    }

    // 完成升级
    static public function afterLvup(&$user)
    {
        $auths = UserAuthEvent::getAuths();
        $authLang = UserAuthEvent::$authlang;
        foreach ($auths as $key => $level) {
            if ($user['level'] == $level){
               !empty($authLang[$key]) && $hasAuth[] = $authLang[$key];
            }
        }

        if ($hasAuth){
            $content = sprintf("恭喜你等级到达%s级了，获得%s特权", $user['level'], implode('/', $hasAuth));
            event('UserNotice')->addSystem($user['uid'], $content);
        }
    }

    // 获得认证
    static public function finishAuthicon($uid, $auth_icon_id)
    {
        $icon = event('IconPacks')->getIconById($auth_icon_id);
        $content = sprintf("恭喜你获得官方%s认证", $icon['name']);
        event('UserNotice')->addSystem($uid, $content);
    }

}